package app

import (
	"fmt"
	"html/template"
	"log"
	"net/http"
	"net"
)

func (G *Global) Nslookup(w http.ResponseWriter, r *http.Request) {
	if r.Method == "GET" {
		//fmt.Print("获取页面dns解析页面")
		t, template_err := template.ParseFiles("templates/tools/nslookup.html", "templates/common/head.html", "templates/common/foot.html")
		if template_err != nil {
			log.Println(template_err.Error())
			fmt.Fprintf(w, template_err.Error())
		} else {
			t.Execute(w, G)
		}
		}
	if r.Method == "POST" {

		domain := r.PostFormValue("domain")
	    fmt.Println(domain)
		if domain == "" {
			fmt.Fprint(w,"请输入正确的域名")
			fmt.Print("输入域名错误")
		} else {
			LOCKUP_INFO, err := net.LookupHost(domain) //解析域名
			if err == nil {
				fmt.Fprintf(w, LOCKUP_INFO[0])
				fmt.Print("解析域名",domain,LOCKUP_INFO)
			}
		}
	}
}


